import got from "got";
import { readFileByType, writeFileByType } from "./util";
const prefixUrl = process.env.ICAN_PREFIXURL;
const getAddressUrl = process.env.ICAN_GET_ADDRESS;
const token = readFileByType('access_token')

const getAddress = async () => {
  const headers = {
    authorization: `Bearer ${token}`
  }
  const postUrl = `${prefixUrl}${getAddressUrl}`;
  try {
    const res = await got.get(postUrl, {
      headers,
    });
    const jsonData = JSON.parse(res.body)
    writeFileByType('address', jsonData.data, 'json')
    return res;
  } catch (error) {
    console.error(error);
  }
}

export { getAddress }